package com.lee.dynamic.web;

import com.lee.dynamic.model.Person;
import com.lee.dynamic.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("person")
public class PersonController {

    @Autowired
    private IPersonService personService;

    @RequestMapping("list")
    @ResponseBody
    public List<Person> list() {
        List<Person> persons = personService.listPerson();
        return persons;
    }

    @RequestMapping("listMaster")
    @ResponseBody
    public List<Person> listMaster() {
        List<Person> persons = personService.listMasterPerson();
        return persons;
    }

    @RequestMapping("update/{id}/{age}")
    @ResponseBody
    public int update(@PathVariable("id")int id, @PathVariable("age") int age) {
        int count = personService.update(id, age);
        return count;
    }
}
